﻿using CleanArchitecture.Infrastructure.Interfaces;
using CleanArchitecture.Infrastructure.StartupConfig;
using CleanArchitecture.Web.Controllers.Backend;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;

namespace CleanArchitecture.Web.MvcRouteConfig
{
    public partial class BackendRouteProvider : IRouteProvider
    {
        #region Methods

        /// <summary>
        /// Register routes
        /// </summary>
        /// <param name="routeBuilder">Route builder</param>
        public void RegisterRoutes(IRouteBuilder routeBuilder)
        {
            //reorder routes so the most used ones are on top. It can improve performance
            //areas
            //routeBuilder.MapRoute(name: "areaRoute", template: "{area:exists}/{controller=BackendHome}/{action=Index}/{id?}");

            //login
            routeBuilder.MapRoute("BackendLogin", DefaultRoutePath.LoginPath,/*"login/",*/
                new { controller = "BackendLogin", action = "Index" });
            #region BackendHome
            routeBuilder.MapRoute("BackendHome", "backend/",
                new { controller = "BackendHome", action = "Index" });
            routeBuilder.MapRoute("BackendWelcome", "/backendhome.html",
                new { controller = "BackendHome", action = "Welcome" });
            routeBuilder.MapRoute("AccountSetting", "/account/setting",
                new { controller = "BackendAdminUser", action = "AccountSetting" });
            routeBuilder.MapRoute("AccountSettingChangePassword", "/account/setting/changepwd",
                new { controller = "BackendAdminUser", action = "AccountChangePassword" });
            #endregion

            #region Backend SystemManage
            routeBuilder.MapRoute("SystemDataDicManage", "/system/datadic",
                new { controller = "SystemManage", action = "SystemDataDic" });
            routeBuilder.MapRoute("SystemDataDicOrganizeManageEdit", BackendAuthorizeRouteConfig.BackendSystem_OrganizeManageEdit,
    new { controller = "SystemManage", action = "SystemDataDicOrganizeManageEdit" });
            routeBuilder.MapRoute("SystemModuleManage", "/system/systemmodule",
                new { controller = "SystemManage", action = "SystemModuleManage" });
            routeBuilder.MapRoute("SystemModuleEditView", "/system/systemmodule/edit",
                new { controller = "SystemManage", action = "SystemModuleEditView" });
            routeBuilder.MapRoute("SystemAuthorizeManage", "/system/moduleauthorize",
                new { controller = "SystemManage", action = "SystemAuthorizeManage" });
            routeBuilder.MapRoute("FrontColumnAuthorizeManage", "/system/columnauthorize",
                new { controller = "SystemManage", action = "FrontColumnAuthorizeManage" });
            routeBuilder.MapRoute("WebsiteManage", BackendAuthorizeRouteConfig.BackendSystem_WebsiteManage,
                new { controller = "SystemManage", action = "WebsiteManage" });
            routeBuilder.MapRoute("WebsiteManageEdit", BackendAuthorizeRouteConfig.BackendSystem_WebsiteManageEdit,
                new { controller = "SystemManage", action = "WebsiteManageEdit" });
            routeBuilder.MapRoute("AdminUserManage", BackendAuthorizeRouteConfig.BackendAdminUser_AdminUserManage,
                new { controller = "BackendAdminUser", action = "AdminUserManage" });
            routeBuilder.MapRoute("AdminUserManageEdit", BackendAuthorizeRouteConfig.BackendAdminUser_AdminUserManageEdit,
                new { controller = "BackendAdminUser", action = "AdminUserManageEdit" });
            routeBuilder.MapRoute("AdminRoleManage", BackendAuthorizeRouteConfig.BackendAdminUser_AdminRoleManage,
                new { controller = "BackendAdminUser", action = "AdminRoleManage" });
            routeBuilder.MapRoute("AdminRoleManageEdit", BackendAuthorizeRouteConfig.BackendAdminUser_AdminRoleManageEdit,
                new { controller = "BackendAdminUser", action = "AdminRoleManageEdit" });
            #endregion
            //System Task Route
            routeBuilder.MapRoute("SystemScheduleTask", DefaultRoutePath.ScheduleTaskPath,
                new { controller = "SystemScheduleTask", action = "RunTask" });

            //Business Parts
            #region ColumnMange
            routeBuilder.MapRoute("BackendColumnManage", BackendAuthorizeRouteConfig.BackendBusiness_ColumnManage,
                new { controller = "BackendBusiness", action = "BackendColumnManage" });
            routeBuilder.MapRoute("BackendColumnManageEdit", BackendAuthorizeRouteConfig.BackendBusiness_ColumnManageEdit,
                new { controller = "BackendBusiness", action = "BackendColumnManageEdit" });
            #endregion
            #region Backend NewsManage
            routeBuilder.MapRoute("BackendNewsManage", BackendAuthorizeRouteConfig.BackendBusiness_NewsManage,
                new { controller = "BackendBusiness", action = "BackendNewsManage" });
            routeBuilder.MapRoute("BackendNewsManageEdit", BackendAuthorizeRouteConfig.BackendBusiness_NewsManageEdit,
                new { controller = "BackendBusiness", action = "BackendNewsManageEdit" });
            #endregion
            #region Backend BlogManage
            routeBuilder.MapRoute("BackendBlogManage", BackendAuthorizeRouteConfig.BackendBusiness_BlogManage,
                new { controller = "BackendBusiness", action = "BackendBlogManage" });
            routeBuilder.MapRoute("BackendBlogManageEdit", BackendAuthorizeRouteConfig.BackendBusiness_BlogManageEdit,
                new { controller = "BackendBusiness", action = "BackendBlogManageEdit" });
            #endregion
            #region Backend ResourceManage
            routeBuilder.MapRoute("BackendResourceManage", BackendAuthorizeRouteConfig.BackendBusiness_ResourceManage,
                new { controller = "BackendBusiness", action = "BackendResourceManage" });
            routeBuilder.MapRoute("BackendResourceManageEdit", BackendAuthorizeRouteConfig.BackendBusiness_ResourceManageEdit,
                new { controller = "BackendBusiness", action = "BackendResourceManageEdit" });
            #endregion
            #region Backend AdvertiseManage
            routeBuilder.MapRoute("BackendAdvertiseManage", BackendAuthorizeRouteConfig.BackendBusiness_AdvertiseManage,
                new { controller = "BackendBusiness", action = "BackendAdvertiseManage" });
            routeBuilder.MapRoute("BackendAdvertiseManageEdit", BackendAuthorizeRouteConfig.BackendBusiness_AdvertiseManageEdit,
                new { controller = "BackendBusiness", action = "BackendAdvertiseManageEdit" });
            #endregion
            #region Backend CommentManage
            routeBuilder.MapRoute("BackendCommentManage", BackendAuthorizeRouteConfig.BackendBusiness_CommentManage,
                new { controller = "BackendBusiness", action = "BackendCommentManage" });
            #endregion
            
        }

        /// <summary>
        /// Register routes
        /// DavidLee : 2020/04/16 管理后端路由注册请在上面RegisterRoutes中注册实现
        /// 此方法只为前端(Frontend)中进行路由注册，因为这个方法是后加的，已经写好的路由注册不想再更改
        /// 不要问我为什么，我懒！
        /// 而增加此方法的目的是为前端页面(Frontend)配合Column的UrlRoute及Layout实现路由动态匹态及跳转
        /// </summary>
        /// <param name="endpointRouteBuilder">Route builder</param>
        public void RegisterEndpointRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
            //throw new System.NotImplementedException();
        }
        #endregion

        #region Properties

        /// <summary>
        /// Gets a priority of route provider
        /// </summary>
        public int Priority
        {
            get { return 1; }
        }

        #endregion
    }
}
